import base64
import copy
import hashlib
import string
import urllib.parse as up
import time

import base36
from curl_cffi import requests
import math
import io
import struct
import hmac
from util import android_id, get_md5, generate_sequence_id, deal_b2, deal_c2_str_d2, construct_data
from requests.adapters import HTTPAdapter
from urllib3.util.ssl_ import create_urllib3_context
import random
from urllib.parse import urlparse, parse_qs, urlencode, urlsplit, parse_qsl
from Crypto.Cipher import ARC4
import binascii
import zlib
import json

key_ = base64.b64decode(
    'NDRlNzE1YTZlMzIyY2NiN2QwMjhmN2E0MmZhNTUwNDAAAAAAAAAAADdkMDA2OTY2MGM5YjVkMzIwNzRmYWNmMzdjMzczOGExAAAAAAAAAAA4MDMwNmY0MzcwYjM5ZmQ1NjMwYWQwNTI5Zjc3YWRiNg==')
types = [[0xcd], [0x20, 1], [150, 175, 4], [0xC1, 0xA4, 0x53, 0xCC], [0x60, 0x2C, 0x95, 0xF2, 0x6E],
         [0xD8, 0x0E, 0xF7, 0xA1, 0xA4, 0x2D], [0xD3, 0x97, 0x56, 0xE5, 0x85, 0x9C, 0xF8]]

APPVERSION = '12.3.1'

PIC_DATA = {
    "a1": 0,
    "a10": 400,
    "a2": "com.jingdong.app.mall",
    "a11": "ef755e50e6d6ef0505ed4918cb20525adc443a90",
    "a3": "E0D1A70367C58D5D41C4678DFD05F84F",
    "a4": "99032",
    "a5": "12.3.1",
    "a6": "SHYra41srNERLLqk+81b5sz4JxU1zJi2kVumhJmc6UPsLL4DQT7FJvry+/bagN2B",
    "a7": "rFE+4r8pg+E1y9G8SDYv4Vfz2+HyGSyFvmdPOyNIEWxnFf5+TTp0WK5gIJoz1J9C",
    "a8": 1702879481846
}

META_DATA = {
    "b1": "5022fc2c-778f-4e69-98d5-a713375bc559",
    "b2": "3.2.6.2_0",
    "b3": "2.1",
    "b4": "",
    "b5": "",
    "b7": "",  # timestamp
}

DEVICE_INFO = [
    ['HuaWei/EMOTION/', 'V12'],
    ['Lenovo/VIBE/', 'V12'],
    ['Zte/NUBIA/', 'V12'],
    ['Meizu/FLYME/', 'V12'],
    ['Oppo/COLOROS/', 'V12'],
    ['vivo/FUNTOUCH/', 'V12'],
    ['XiaoMi/MIUI/', 'V12'],
]

CPU_INFO = [
    'sdm660',
    'sdm710',
    'sdm770',
    'sdm865',
    'sdm880',
    'sdm870',
    'sdm810',
    'sdm630'
]
GaddArr = [
    0x78, 0x8a, 0x04, 0x09, 0xa5, 0x38, 0xff, 0x39, 0xa0, 0xb9, 0x20, 0xc0, 0xe7, 0xd5, 0xe8, 0xec,
    0xae, 0x1d, 0x24, 0xf0, 0x75, 0x9a, 0x5b, 0xa3, 0xfd, 0xb8, 0x2a, 0x68, 0x29, 0xe1, 0xa6, 0x38
]

GxorArr = [
    0x4c, 0x90, 0x7a, 0x16, 0x1b, 0xc9, 0xb6, 0x69, 0x7a, 0x65, 0x84, 0x73, 0x82, 0xc3, 0x04, 0x11,
    0x94, 0xab, 0x22, 0xdb, 0x6c, 0xed, 0x9d, 0x80, 0xf1, 0x72, 0xc0, 0x73, 0xeb, 0x47, 0x4a, 0x5f
]


def cycle(plainText):
    '''
    功能：so函数将明文循环打乱，再转base64
    :param plainText:
    :return:
    '''
    plainText = binascii.hexlify(plainText.encode()).decode()
    '''
    这个好像是上面循环生成的
    0000: 2B 25 23 17 44 21 4B EF F6 1C 23 3E 37 92 44 68    +%#.D!K...#>7.Dh
    0010: A5 3D CC 7F BB 0F D9 88 EE 9A E9 5A 00 00 00 00    .=.........Z....
    0020: 2A 02 28 2F F0 F4 FF BF 00 50 21 40 01 00 00 00    *.(/.....P!@....
    0030: 80 F5 FF BF E3 01 00 00 AC 7B 90 7D 01 00 00 00    .........{.}....
    0040: 80 F5 FF BF 0B 0E 01 40 E3 01 00 00 00 00 00 00    .......@........
    0050: 08 10 21 40 40 00 21 40 00 00 00 00 00 00 00 00    ..!@@.!@........
    0060: 10 0B FE FF E3 01 00 00 00 50 21 40 02 00 00 00    .........P!@....

    0000: 38 30 33 30 36 66 34 33 37 30 62 33 39 66 64 35    80306f4370b39fd5
    0010: 36 33 30 61 64 30 35 32 39 66 37 37 61 64 62 36    630ad0529f77adb6

    '''
    v21 = "2b 25 23 17 44 21 4b ef f6 1c 23 3e 37 92 44 68 a5 3d cc 7f bb 0f d9 88 ee 9a e9 5a 00 00 00 00 2a 02 28 2f f0 f4 ff bf 00 50 21 40 01 00 00 00 80 f5 ff bf e3 01 00 00 ac 7b 90 7d 01 00 00 00 80 f5 ff bf 0b 0e 01 40 e3 01 00 00 00 00 00 00 08 10 21 40 40 00 21 40 00 00 00 00 00 00 00 00 10 0b fe ff e3 01 00 00 00 50 21 40 02 00 00 00".replace(
        " ", "")
    a2 = "38 30 33 30 36 66 34 33 37 30 62 33 39 66 64 35".replace(" ", "")

    result = ""
    '''
    循环过程中r3就是作为传入字符串索引的
    '''
    v15 = 0
    while v15 < math.floor(len(plainText) / 2):
        r2 = v15 & 15  # and r2, r3, #0xf
        # v16 = v21[32:] + (v15 & 15)
        v16 = v21[64 + r2 * 2:64 + r2 * 2 + 8]  # 这个放在r2 m0xbffff4c1
        v17 = v15 & 7  # 这个就是r1 and r1, r3, #7
        v18 = v21[v21.index(v16) - 40:v21.index(v16) - 40 + 2]  # ldrb r2, [r2, #-0x14] [0xbffff4ac] => 0x37
        r0 = ((int(v18, 16) ^ int(plainText[v15 * 2:v15 * 2 + 2], 16)) ^ int(a2[2 * v17: 2 * v17 + 2], 16)) + int(v18,
                                                                                                                  16)
        b1 = int(v18, 16) ^ r0  # v18 ^ result
        b1 = hex(b1).replace("0x", "")[-2:] if len(hex(b1).replace("0x", "")) >= 2 else "0" + hex(b1).replace("0x",
                                                                                                              "")  # LOBYTE是取低位一个字节
        rr = int(b1, 16) ^ int(a2[2 * v17: 2 * v17 + 2], 16)
        hex_rr = hex(rr).replace("0x", "") if len(hex(rr).replace("0x", "")) >= 2 else "0" + hex(rr).replace("0x", "")
        result += hex_rr
        v15 += 1
    a = bytes.fromhex(result)
    return base64.b64encode(a).decode()


def getSign(functionId, body, client, clientVersion, uuid):
    st = str(int(time.time() * 1000))
    plainText = 'functionId=%s&body=%s&uuid=%s&client=android&clientVersion=%s&st=%s&sv=111' % (
        functionId, body, uuid, clientVersion, st)
    base64_str = cycle(plainText)
    md5 = hashlib.md5()
    md5.update(base64_str.encode())
    md5_ = md5.hexdigest()
    return "st=" + st + "&sign=" + md5_ + "&sv=111"


class Cipher:
    f7339a = ['K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'U',
              'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'e', 'f',
              'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+',
              '/']
    aaf = bytearray(128)

    def __init__(self):
        try:
            self.c()
            self.m23208pf()
        except Exception as e:
            print(e)

    @staticmethod
    def m23208pf():
        i = 0
        i2 = 0
        while i2 <= len(Cipher.aaf) - 1:
            Cipher.aaf[i2] = -1
            i2 += 1

        while i <= len(Cipher.f7339a) - 1:
            Cipher.aaf[ord(Cipher.f7339a[i])] = i
            i += 1

    @staticmethod
    def decode(s):
        bytearr_out = io.BytesIO()
        bytes_in = bytearray(s, 'utf-8')
        bArr = bytearray(len(bytes_in))
        for i in range(len(bytes_in)):
            bArr[i] = Cipher.aaf[bytes_in[i]]
        i2 = 0
        while i2 <= len(bArr) - 1:
            bArr2 = bytearray(3)
            i3 = 0
            for i4 in range(3):
                i5 = i2 + i4
                i6 = i5 + 1
                if i6 <= len(bArr) - 1 and bArr[i6] >= 0:
                    bArr2[i4] = (bArr[i5] & 255) << ((i4 * 2) + 2) & 255 | (bArr[i6] & 255) >> ((2 - (i4 + 1)) * 2 + 2)
                    i3 += 1
            for i7 in range(i3):
                bytearr_out.write(bytes([bArr2[i7]]))
            i2 += 4
        return bytearr_out.getvalue()

    @staticmethod
    def encrypt(bArr):
        sb = []
        for i2 in range(0, len(bArr), 3):
            bArr2 = bytearray(4)
            b2 = 0
            for i3 in range(3):
                i4 = i2 + i3
                if i4 <= len(bArr) - 1:
                    bArr2[i3] = (b2 | ((bArr[i4] & 255) >> ((i3 * 2) + 2))) & 255
                    b2 = (((bArr[i4] & 255) << (((2 - i3) * 2) + 2)) & 255) >> 2
                else:
                    bArr2[i3] = b2
                    b2 = 64
            bArr2[3] = b2
            for i5 in range(4):
                if bArr2[i5] <= 63:
                    sb.append(Cipher.f7339a[bArr2[i5]])
                else:
                    sb.append('=')
        return ''.join(sb)

    @staticmethod
    def c():
        i2 = 0
        i3 = 0
        while i3 <= len(Cipher.aaf) - 1:
            Cipher.aaf[i3] = 255
            i3 += 1
        while i2 <= len(Cipher.f7339a) - 1:
            Cipher.aaf[ord(Cipher.f7339a[i2])] = i2
            i2 += 1


class jdGsService():
    def __init__(self):
        self.arr = ["86=336002=小米=3=1920=1080=Xiaomi=MIUI_7.0",
                    "86=067002=小米=2S=1280=720=Xiaomi=MIUI_7.0",
                    "86=568702=小米=4=1920=1080=Xiaomi=MIUI_8.0",
                    "86=971802=小米=5S=1920=1080=Xiaomi=MIUI_9.0",
                    "86=778902=oppo=R7s=1920=1080=OPPO=ColorOS_13.0",
                    "86=367003=oppo=R9s=1920=1080=OPPO=ColorOS_14.0",
                    "86=582702=联想=P70-t=1280=720=Lenovo=MyUI_3.0",
                    "86=478302=联想=A808t=1280=720=Lenovo=MyUI_3.0",
                    "86=558302=联想=A936=1280=720=Lenovo=MyUI_4.0",
                    "86=682001=中兴=U9815=1280=720=ZTE=MiFavor_1.0",
                    "86=579002=锤子=YQ601=1920=1080=Smartisan=SmartisaOS_2.0",
                    "86=438702=华为=H60-L11=1920=1080=HUAWEI=harmonyOS_1.0",
                    "86=200203=华为=EVA-AL10=1920=1080=HUAWEI=harmonyOS_2.0",
                    "86=333903=华为=FRD-AL00=1920=1080=HUAWEI=harmonyOS_1.0",
                    "86=370903=vivo=vivo X9=1920=1080=vivo=OriginOS_5.0",
                    "86=311603=vivo=X7Plus=1920=1080=vivo=OriginOS_4.0",
                    "86=106903=魅族=M685Q=1920=1080=Meizu=Flyme_7.0",
                    "86=410503=魅族=M6210=1920=1080=Meizu=Flyme_8.0",
                    "86=372603=魅族=M5=1920=1080=Meizu=Flyme_9.0",
                    "35=195308=三星=SM-G9350=2560=1440=Samsung=Tizen_1.0",
                    "35=346108=三星=SM-C9000=1920=1080=Samsung=Tizen_2.0"]
        pass

    def getJdgs(self, eid, url, body):
        b7 = int(time.time() * 1000)
        appver = "15.0.25"
        postStr = self.getfinalPostStr(url, body)
        riskStr = self.getRiskCombine(eid, appver, b7)
        b5 = self.getB5(postStr)

        res = '''{{"b1":"8ee3256e-140a-40ca-9cb6-ddfdea746143","b2":"3.2.9.3_0","b3":"2.1","b4":"{b4}","b5":"{b5}","b7":"{b7}"}}'''.format(
            b4=riskStr, b5=b5, b7=b7)
        b6 = self.getB6(res)
        return '''{{"b1":"8ee3256e-140a-40ca-9cb6-ddfdea746143","b2":"3.2.9.3_0","b3":"2.1","b4":"{b4}","b5":"{b5}","b7":"{b7}","b6":"{b6}"}}'''.format(
            b4=riskStr, b5=b5, b7=b7, b6=b6)

    def getfinalPostStr(self, uri, body, method='POST'):
        sha256_ = hashlib.sha256(body.encode())
        encrypt_body = sha256_.hexdigest()
        # URL地址
        # 提取URL参数部分
        query_string = urlsplit(uri).query
        # 将查询字符串解析成字典形式
        params = dict(parse_qsl(query_string))
        params[encrypt_body] = ''
        # 根据键名进行排序
        sorted_params = sorted(params.items(), key=lambda x: x[0])
        query_string = urlencode(sorted_params)
        path = urlparse(uri).path
        return method + " " + path + " " + query_string

    def rc4encrypt(self, key, plaintext):
        cipher = ARC4.new(key)
        ciphertext = cipher.encrypt(plaintext)
        return ciphertext

    def rc4decrypt(self, key, ciphertext):
        cipher = ARC4.new(key)
        plaintext = cipher.decrypt(ciphertext)
        return plaintext

    def getRiskCombine(self, eid, appver, b7):
        newT = b7 ^ 47699
        # newT = 1727414339302
        fistinstalltime = newT - 700000
        device = random.choice(self.arr)
        brand2 = device.split("=")[6]
        opSys = device.split("=")[7]
        deviceName = device.split("=")[3]
        deviceName = device.split("=")[3]
        random_externDisk = random.randint(0, 540200304) * 100 + random.randint(0, 100) + 5400000000
        md5_ = hashlib.md5(str(random_externDisk).encode())
        random_cid = md5_.hexdigest()
        return json.dumps({"e1": eid, "e2": "", "e3": newT, "e5": "00000000-0000-0000-0000-000000000000"},
                          separators=(',', ':'), ensure_ascii=False)



    def getB5(self, postStr):
        padding = self.getPadding(postStr)
        data = postStr.encode() + bytes(padding)
        sha1_ = hashlib.sha1(data)
        return sha1_.hexdigest()
        pass

    def getB6(self, postStr):
        return self.getB5(postStr)
        pass

    def getPadding(self, postStr):
        data = self.calcXor(postStr.encode())
        md5_ = hashlib.md5(bytes(data))
        return self.jdgsSha256(md5_.hexdigest())
        pass

    def jdgsSha256(self, md5_):
        GaddArr = [120, 138, 4, 9, 165, 56, 255, 57, 160, 185, 32, 192, 231, 213, 232, 236, 174, 29, 36, 240, 117, 154,
                   91, 163, 253, 184, 42, 104, 41, 225, 166, 56]
        GxorArr = [76, 144, 122, 22, 27, 201, 182, 105, 122, 101, 132, 115, 130, 195, 4, 17, 148, 171, 34, 219, 108,
                   237, 157, 128, 241, 114, 192, 115, 235, 71, 74, 95]
        value = hashlib.sha256(bytes.fromhex(md5_))
        ori256 = bytes.fromhex(value.hexdigest())
        result = [0] * 32
        for i in range(len(ori256)):
            temp = (ori256[i] + GaddArr[i]) & 255
            temp = temp ^ GxorArr[i]
            result[i] = temp
        return result

    def calcXor(self, params):
        appkey_xor = [84, 48, 28, 112, 81, 2, 4, 81, 65, 116, 114, 65, 40, 90, 2, 66, 9, 37, 120, 124, 72, 7, 25, 107,
                      11, 84, 13, 9, 92, 35, 91, 117, 114, 83, 7, 96]
        bArrSize = len(params)
        a4 = len(appkey_xor)
        size = max(bArrSize, a4)
        result = [0] * size
        v13 = 0
        v14 = 0
        v15 = 0
        v11 = 0
        v10 = 0
        v12 = 0
        if bArrSize <= a4:
            while True:
                v13 = v10 % bArrSize
                v14 = appkey_xor[v10]
                v15 = params[v13]
                v10 = v10 + 1
                result[v13] = (v14 ^ v15) & 255
                if (a4 == v10):
                    break
        else:
            while True:
                v11 = params[v10]
                v12 = appkey_xor[v10 % a4]
                v15 = params[v10 % bArrSize]
                result[v10] = (v12 ^ v11) & 255
                v10 = v10 + 1
                if (bArrSize == v10):
                    break
        return result


def get_length_prefix(data):
    length_prefix = struct.pack('!I', len(data))
    return length_prefix


def hmac_sha256(key, message):
    hmac_digest = hmac.new(key, message, hashlib.sha256).digest()
    return hmac_digest


def sign_uuid():
    userKey = android_id()
    # APP签名
    packagesign = "30820247308201b0a00302010202044d6c5dae300d06092a864886f70d01010505003068310b300906035504061302636e3110300e060355040813076265696a696e67310e300c060355040713056368696e613111300f060355040a13086a696e67646f6e673111300f060355040b13086a696e67646f6e673111300f060355040313086a696e67646f6e67301e170d3131303330313032343530325a170d3338303731373032343530325a3068310b300906035504061302636e3110300e060355040813076265696a696e67310e300c060355040713056368696e613111300f060355040a13086a696e67646f6e673111300f060355040b13086a696e67646f6e673111300f060355040313086a696e67646f6e6730819f300d06092a864886f70d010101050003818d00308189028181008c470af7c751ee12edbae8dd9e7c98fa60d3c631efa0f7172ed36c86bb85c8288391e718c05fdbef008d61f2e8fce4ef4457a69ae5a2fa53ead0c806c18f8b475847c07bf4451d82845efc30d5fc4aa2500f4bc84234a36749e83a9361c9ec89771a762e3d791eebf3154c2e95d06df95be68b4a4dcff33ef1ba5d6d90758b6d0203010001300d06092a864886f70d010105050003818100821db5cf6e40d98e9b0e2a6a8ad09a0c52435e82df79d16fa8a3fea8f135f40cceedd3e98c18d0ef4bb5f5cfeccea3311d14e48cce863f520bc8b71491287fe5559d06a8a20446e168da5f488f971f473220ce619976e2286ce353b6882016d9978309edb3200a7aa0a5d5c8e39a7d9d612d9a6fc210d878f40d0860a59cd432"
    userKey_bytes = bytes.fromhex(userKey)
    packagesign_bytes = bytes.fromhex(packagesign)
    m = hmac.new(userKey_bytes, digestmod=hashlib.sha256)
    m.update(get_length_prefix(packagesign_bytes)[:4])
    m.update(packagesign_bytes)
    return m.digest().hex()[:16]


ORIGIN_CIPHERS_LIST = [
    "ECDHE+AESGCM", "ECDHE+CHACHA20", "DHE+AESGCM", "DHE+CHACHA20",
    "ECDH+AESGCM", "DH+AESGCM", "ECDH+AES", "DH+AES", "RSA+AESGCM", "RSA+AES"
]


class DESAdapter(HTTPAdapter):
    def __init__(self, *args, **kwargs):
        ORIGIN_CIPHERS = ":".join(random.sample(ORIGIN_CIPHERS_LIST, random.randint(2, len(ORIGIN_CIPHERS_LIST))))
        CIPHERS = ORIGIN_CIPHERS.split(':')
        random.shuffle(CIPHERS)
        CIPHERS = ':'.join(CIPHERS)
        self.CIPHERS = CIPHERS + ':!aNULL:!eNULL:!MD5'
        super().__init__(*args, **kwargs)

    def init_poolmanager(self, *args, **kwargs):
        context = create_urllib3_context(ciphers=self.CIPHERS)
        kwargs['ssl_context'] = context
        return super(DESAdapter, self).init_poolmanager(*args, **kwargs)

    def proxy_manager_for(self, *args, **kwargs):
        context = create_urllib3_context(ciphers=self.CIPHERS)
        kwargs['ssl_context'] = context
        return super(DESAdapter, self).proxy_manager_for(*args, **kwargs)


# 支付签名
def get_paysiyn(orderid, ordertype, factprice):
    # orderid:订单号   ordertype：订单类型    factprice：实付金额
    data = 'jd_android_app4;' + orderid + ';' + ordertype + ';' + factprice
    sign = get_md5(data=data)
    return sign


def sha1_hash(input_string):
    sha1 = hashlib.sha1()
    sha1.update(input_string)
    return sha1.hexdigest()


def sha256_hash(input_string):
    sha256 = hashlib.sha256()
    sha256.update(bytes.fromhex(input_string))
    return sha256.hexdigest()


def body_dec(data):
    body_key = "KLMNOPQRSTABCDEFGHIJUVWXYZabcdopqrstuvwxefghijklmnyz0123456789+/"
    decoded_custom = data.translate(
        bytes.maketrans(body_key.encode('utf-8'), b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"))
    decoded_bytes = base64.b64decode(decoded_custom)
    return decoded_bytes.decode('utf-8')


def body_enc(data):
    body_key = "KLMNOPQRSTABCDEFGHIJUVWXYZabcdopqrstuvwxefghijklmnyz0123456789+/"
    encoded_bytes = base64.b64encode(data.encode('utf-8'))
    encoded_custom = encoded_bytes.translate(
        bytes.maketrans(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", body_key.encode('utf-8')))
    return encoded_custom.decode('utf-8')


def c():  # 定义函数 c()
    characters = string.ascii_letters + string.digits  # 包括小写字母、大写字母和数字
    return ''.join(random.choice(characters) for _ in range(10))


def d():
    return "{:02x}".format(random.randint(1, 6))


def g(s):
    try:
        crc32 = zlib.crc32(s.encode()) & 0xffffffff
        l2 = base36.dumps(crc32)
        if len(l2) > 7:
            return l2[-7:]
        elif len(l2) < 7:
            return '0' * (7 - len(l2)) + l2
        else:
            return l2
    except Exception:
        return ""


def get_whwswswws(wifi_mac, uuid, sequence_id, proxy=None, eid="", wskey=""):
    url = "https://blackhole.m.jd.com/getinfo"
    # 获取完整的POST数据
    post_data, installid = construct_data(wifi_mac, uuid, sequence_id)
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded; Charset=UTF-8',
        'Accept': '*/*',
        'Accept-Language': 'zh-cn',
        'Referer': 'https://blackhole.m.jd.com/getinfo',
        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; ALN-AL80 Build/HUAWEIALN-AL80)',
        'Host': 'blackhole.m.jd.com',
        'cookie': "eid=" + eid + "; wskey=" + wskey + "; whwswswws="
    }
    # 发送HTTP请求
    response = requests.post(url, data=post_data, headers=headers, verify=False, impersonate="chrome99_android")
    #  #print(response.text)
    # 解析JSON响应
    json_data = response.json()
    # 返回特定属性的值
    whwswswws = json_data.get("whwswswws", None)
    return whwswswws


def get_JMA(wifi_mac, uuid, eid, wskey):
    c2 = c()  # 使用前面定义的 c() 函数
    # c2 = 'SULqlotVzo'
    str1 = str(int(time.time() * 1000))  # 获取当前时间的毫秒表示
    # str1 = '1724503079720'
    d2 = d()  # 使用前面定义的 d() 函数
    d2 = "06"
    str2 = c2 + str1 + d2  # 拼接字符串
    # print(str2)
    sequence_id = generate_sequence_id()

    # sequence_id = '228cd6827fe2539d5ad748d70d5c0e22a729f'
    uuids = '-' + wifi_mac + '-' + uuid + '-' + sequence_id
    # print(deal_c2_str_d2(c2, str, d2))
    # String f2 = f(c.d(context) + com.jd.stat.security.b.l()); 由于com.jd.stat.security.b.l())返回的是空字符串，c.d(context)为固定字符com.jingdong...所以这里就不加了,直接写死
    str3 = "JD0121"
    str4 = str3 + g(str3)
    whws = get_whwswswws(wifi_mac, uuid, sequence_id, eid=eid, wskey=wskey)
    str4 = str4 + "~" + whws
    # print('最终结果', str4)
    return str4
